/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License.You may obtain a copy of the License at
	http://www.mozilla.org/MPL/MPL-1.1.html
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import org.aswing.AbstractListCell;
import org.aswing.Component;
import org.aswing.JLabel;
import org.aswing.JList;

import fvaswing.utils.tracer.FvTracerMessage;

/**
 * Cell implementation {@link fvaswing.utils.tracer.FvAsWingTracer} logging cell.
 *
 * @author Romain Ecarnot
 */
class fvaswing.utils.tracer.FvTracerCell extends AbstractListCell
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _view : JLabel;
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	public function FvTracerCell()
	{
		super();
	}
	
	/**
	 * Return the represent component of this cell.
	 * 
	 * @return a component that represent this cell.
	 */
	public function getCellComponent() : JLabel
	{
		if( _view == null )
		{
			_view = new JLabel("...", JLabel.LEFT );
		}
		return _view;
	}
	
	/**
	 * Sets the table cell status, include the owner-JList isSelected and row position.
	 * 
	 * @param the cell's owner, a JList
	 * @param isSelected true to set the cell selected, false to set not selected.
	 * @param index the index of the list item
	 */
	public function setListCellStatus( list : JList, isSelected : Boolean ) : Void
	{
		var com : Component = getCellComponent();
		com.setBackground( value.color );
		com.setFont(list.getFont());
	}
	
	/**
	 * Sets the value of this cell.
	 * 
	 * @param value which should represent on the component of this cell.
	 */
	public function setCellValue( v : FvTracerMessage ) : Void
	{
		if( getCellComponent().getText() != v.message )
		{
			value = v;
			getCellComponent().setText( v.message );
			getCellComponent().setOpaque( true );
			getCellComponent().repaint();
		}
	}
}